
public class ListOfObjects {


        private int size;
        private Object [] obj; 
        private int nbOfObjects;
        
        public ListOfObjects(){
                size = 0;
                nbOfObjects = 0;
                obj = new Object[size];
        }
    public ListOfObjects(int n){
                size = n;
                nbOfObjects = 0;
                obj = new Object[n];
        }
    
        
        public boolean full () {
                return nbOfObjects == size;
                }
        public boolean empty () {
                return nbOfObjects == 0;
                }
        
        public Object retrieve (int nbOfObject) {
                        return obj[nbOfObject];
                }
        
                
                
        public boolean addObject (String nameOfType) {
        	 if (nbOfObjects < size) {
                 obj[nbOfObjects] = new Object(nameOfType);
                 nbOfObjects++;
                         return true;
              }
             else
                 return false;
         }
        public boolean addObject2 (Object o) { // I added this method because I need it for init and goal
 //to add object to Atom I will search in listOfObject and take copy and add it to Atom
 // example from parser : L4Init.getAtom()[2].getLO().addObject2(L5.findObject("????")); which is  findObject return object     	
                                if (getNbOfObjects() < getSize()) {
                                	
                                        obj[getNbOfObjects()] = o;
                                        nbOfObjects++;
                                                return true  ;
                                }
                                else
                                        return false;
                        }
        


        
                public boolean removeObject (String nameOfType) {
                 
                                for (int i =0 ; i < size; i++) {
                                        if (obj[i].getName().equals(nameOfType) ){
                                                
                                                for(int p = i+1 ; p < nbOfObjects ; p++){
                                                        obj[p-1] = obj[p];
                                                }
                                                nbOfObjects--;  
                                                return true ;
                                        }
                                        
                                }
                                return false ;
                }
                
                public Object findObject(String nameOfObject){ // I changed return type because I need to find object and modify on it 
                        for(int i = 0 ; i < getNbOfObjects() ; i++){ // example findObject("???").getName().  or findObject("???").setName()
                                if(obj[i].getName().equals(nameOfObject)){ 
                                        return obj[i] ;
                                }
                        }
                        return null ;
                }
     public void display(){
        for (int i = 0 ; i <getNbOfObjects() ; i++)
           obj[i].display(); 
      }
    
        public int getSize() {
                return size;
        }
        public Object[] getObj() {
                return obj;
        }
        public int getNbOfObjects() {
                return nbOfObjects;
        }
        public void setSize(int size) {
                this.size = size;
        }
        public void setObj(Object[] obj) {
                this.obj = obj;
        }
        public void setNbOfObjects(int nbOfObjects) {
                this.nbOfObjects = nbOfObjects;
        }
     
}
